package com.wjp.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wjp.bean.Employee;
import com.wjp.bean.EmployeeExample;
import com.wjp.bean.EmployeeExample.Criteria;
import com.wjp.dao.EmployeeMapper;
@Service
public class EmployeeService {
	@Autowired
	EmployeeMapper employeeMapper;
	/**
	 * 查询所有员工
	 * @return
	 */
	public List<Employee> getAll() {
		// TODO Auto-generated method stub
		
		return employeeMapper.selectByExampleWithDept(null);
	}
	public void saveEmp(Employee employee) {
		// TODO Auto-generated method stub
		employeeMapper.insertSelective(employee);
	}
	/**
	 * 检验用户名是否可用
	 * @param empName
	 * @return true 代表可用
	 */
	public boolean checkUser(String empName) {
		// TODO Auto-generated method stub
		 EmployeeExample example =new EmployeeExample();
		 Criteria criteria=example.createCriteria();
		 criteria.andEmpNameEqualTo(empName);
		 long count =employeeMapper.countByExample(example);
		return count==0;
	}
	/**
	 *  根据员工id查询员工
	 * @param id
	 * @return
	 */
	public Employee getEmp(Integer id) {
		// TODO Auto-generated method stub
		Employee employee= employeeMapper.selectByPrimaryKey(id);
		return employee;
	}
	/**
	 * 员工更新
	 * @param employee
	 */
	public void updateEmp(Employee employee) {
		// TODO Auto-generated method stub
		employeeMapper.updateByPrimaryKeySelective(employee);
		
	}
	/**
	 * 员工删除
	 * @param id
	 */
	public void deleteEmp(Integer id) {
		// TODO Auto-generated method stub
		employeeMapper.deleteByPrimaryKey(id);
	}
	/**
	 * 
	 * @param ids
	 */
	public void deleteBath(List<Integer> ids) {
		// TODO Auto-generated method stub
		EmployeeExample example =new EmployeeExample();
		Criteria criteria=example.createCriteria();
		criteria.andEmpIdIn(ids);
		employeeMapper.deleteByExample(example);
	}
	

}
